package com.javaweb.config;

import com.javaweb.filter.TokenFilter;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.Filter;

import static com.javaweb.common.BusinessConstants.UTF_ENCODING;

/**
 * @desc:
 * @author: Ping
 * @date: 2024/10/23 9:44
 */

public class WebDispatcherServlet
        extends AbstractAnnotationConfigDispatcherServletInitializer {
    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[]{SpringConfig.class};
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{ServletContextConfig.class};
    }

    @Override
    protected String[] getServletMappings() {
        // context/root name
        return new String[]{"/"};
    }

    // 配置CharacterEncodingFilter
    @Override
    protected Filter[] getServletFilters() {
        return new Filter[]{
                new CharacterEncodingFilter(UTF_ENCODING)
                 , new TokenFilter()
        };
    }
}
